import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {//默认路由跳转到登录页面
    path: '/',
    redirect:'/login'
  },
  {//登录页面
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue')
  },
  {//主页面
    path: '/mainPage',
    name: 'mainPage',
    component: () => import('../views/mainPage.vue'),
    children:[
        {//我的页面
          path: 'mine',
          name: 'mine',
          component: () => import('../views/mine.vue'),
        },
        {//发现页面,当子组件为空的时候，为默认路由路径
          path:'find',
          name:'find',
          component: () => import('../components/find/find.vue')
        },
        {//云村页面
          path: 'cloud',
          name: 'cloud',
          component: () => import('../components/cloud/cloud.vue')
        },
        {//视频页面
          path: 'movie',
          name: 'movie',
          component: () => import('../components/movie/movie.vue')
        },
        {//搜索页面
          path: 'search',
          name: 'search',
          component: () => import('../views/search.vue')
        }
      ]
  },
  {//音乐播放页面
    path: '/musicDetail',
    name: 'musicDetail',
    component: () => import('../views/musicDetail.vue')
  },
  {
    path: '/notFind',
    name: 'notFind',
    component: () => import('../views/notFind.vue')
  }
]

//这个地方是为了防止频繁触发路由报错的解决方案
const originalPush = VueRouter.prototype.push
   VueRouter.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
  }

const originalReplace = VueRouter.prototype.push
   VueRouter.prototype.replace = function replace(location) {
   return originalReplace.call(this, location).catch(err => err)
  }

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
